﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class LevelSum : MonoBehaviour
{
    public GameLevelItem gameLevelItem;
    public TextButton leftBtn;
    private string leftStr = "5";
    public TextButton rightBtn;
    private string rightStr = "4";
    void Start()
    {
        leftBtn.Init("?", () =>
        {
            if (GameCtrl.Instance.curGameState == GameState.Menu)
                return;
            leftBtn.text.text = getNextNumber(leftBtn.text.text);
            TriggerResult();
        });

        rightBtn.Init("?", () =>
        {
            if (GameCtrl.Instance.curGameState == GameState.Menu)
                return;
            rightBtn.text.text = getNextNumber(rightBtn.text.text);
            TriggerResult();
        });
    }


    private string getNextNumber(string curNumber)
    {
        string nextNumber = "0";
        switch (curNumber)
        {
            case "0":
                nextNumber = "1";
                break;
            case "1":
                nextNumber = "2";
                break;
            case "2":
                nextNumber = "3";
                break;
            case "3":
                nextNumber = "4";
                break;
            case "4":
                nextNumber = "5";
                break;
            case "5":
                nextNumber = "6";
                break;
            case "6":
                nextNumber = "7";
                break;
            case "7":
                nextNumber = "8";
                break;
            case "8":
                nextNumber = "9";
                break;
            case "9":
                nextNumber = "0";
                break;
            default:
                nextNumber = "0";
                break;
        }
        return nextNumber;
    }


    private void TriggerResult()
    {
        if (rightBtn.text.text.Equals(rightStr) && leftBtn.text.text.Equals(leftStr))
        {
            gameLevelItem.TriggerResult(true);
        }
    }
}
